<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>办理超期</title>
    <jsp:include page="/WEB-INF/jsp/header.jsp"/>
    <link rel="stylesheet" type="text/css" href="${basePath}/static/css/production.css?v1"/>
</head>
<body>
<div class="body-main">
    <div>
        <div class="main-title">
				<span class="bus-state">
					<font>办理中</font>
				</span>
            <div class="title-tab">
                <a href="javascript:void(0);"
                   data-status="${proOverDue}">办理超期</a>
            </div>
            <input type="hidden" id="type" name="type" value="${status}">
        </div>
        <div class="titleSearch">
            <form id="titleSearch">
            <div class="layui-inline">
                <label>业务类型：</label>
                <div class="layui-input-inline" style="width:180px;">
                    <div id="business_typeCode">
                        <input type="hidden" name="typeCodeId" class="plug-in-msg"/>
                        <input type="hidden" name="typeCode" id="typeCode" class="plug-in-code"/>
                        <input type="text" readonly placeholder="请选择业态" class="chose-plugIn layui-input"
                               name="businessName">
                        <div class="bus-picker">
                            <div class="bus-picker-tab">
                                <a href="javascript:void(0);" class="active">请选择业态</a>
                            </div>
                            <div class="bus-picker-content"></div>
                        </div>
                    </div>
                </div>
            </div>
            <%--<div class="layui-inline" style="margin-left: 10px;">
                <label>流程人员：</label>
                <div class="layui-input-inline select2-inline">
                    <select class="select-style" id="flowUserId" name="flowUserId" divisionUser-select-law>
                        <option value>请选择</option>
                    </select>
                </div>
            </div>--%>
            <div class="layui-inline" style="margin-left: 10px;">
                <label>签单商务：</label>
                <div class="layui-input-inline select2-inline">
                    <select class="select-style" id="signUserId" name="signUserId">
                        <option value>请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label>客户电话：</label>
                <div class="layui-input-inline">
                    <input type="text" class="input-style" style="width: 150px;" placeholder="电话号码" id="customerPhone"
                           name="customerPhone">
                </div>
            </div>
            <div class="layui-inline">
                <label>签单时间：</label>
                <div class="layui-inline">
                    <input type="text" name="orderTimeStart" placeholder="开始时间" class="Wdate input-style"
                           id="d4311"
                           onFocus="var d4312=$dp.$('d4312'); WdatePicker({onpicked:function(){d4312.focus();}, maxDate:'#F{ $dp.$D(\'d4312\')}', dateFmt:'yyyy-MM-dd'})">
                </div>
                <span>~</span>
                <div class="layui-inline">
                    <input type="text" name="orderTimeEnd" placeholder="结束时间" class="Wdate input-style"
                           id="d4312"
                           onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4311\')}', dateFmt:'yyyy-MM-dd'})">
                </div>
            </div>

            <div class="layui-inline">
                <label>节点更新人：</label>
                <div class="layui-input-inline select2-inline">
                    <select class="select-style" name="latestEndUserId" id="latestEndUserId" divisionUser-select-law>
                        <option value>请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label>订单来源：</label>
                <div class="layui-inline select2-inline">
                    <div class="layui-input-inline">
                        <select class="select-style signUserOrgClass" id="signOrgId" name="signOrgId" >
                            <option value>请选择</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <label>来源方式：</label>
                <div class="layui-input-inline">
                    <select class="select-style" id="originCode" name="originCode">
                        <option value>请选择</option>
                    </select>
                </div>
            </div>
            <%--订单超期和节点超期不要超期状态的搜索条件--%>
            <c:if test="${status != proOverDue && status != nodeOverDue}">
            <div class="layui-inline">
                <label>超期状态：</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <select class="select-style" id="timeStatus" name="timeStatus">
                        <option value>请选择</option>
                        <option value="OVERDUE_STATE1">未超期</option>
                        <option value="NODE_OVERDUE_STATE2">节点超期</option>
                        <option value="ORDER_OVERDUE_STATE2">订单超期</option>
                    </select>
                </div>
            </div>
            </c:if>
            <div class="layui-inline">
                <label>是否看协单：</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <select class="select-style" id="isAssist" name="isAssist" >
                        <option value>请选择</option>
                        <option value="no_assist">不看协单</option>
                        <option value="yes_assist">只看协单</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="margin-left: 12px;">
                <label>关键字：</label>
                <div class="layui-input-inline">
                    <input type="text" class="input-style" style="width: 200px;" placeholder="客户名称/订单编号/生产订单编号"
                           maxlength="50"
                           id="searchKey"
                           name="searchKey">
                </div>
            </div>

            <div class="layui-inline">
                <button class="layui-btn layui-btn-mini layui-btn-normal" type="button" onclick="dataTableReload()">搜索</button>
                <button class="layui-btn layui-btn-mini layui-btn-primary" type="button" onclick="cleanSearch()">清空</button>
                <%--<d:hasUrlAuth authCode="ZZSC_INPROCESS_EXPORT">
                <button class="layui-btn layui-btn-mini layui-btn-green" type="button" onclick="exportIprocessData()">导出</button>
                </d:hasUrlAuth>--%>
            </div>
            </form>
        </div>
        <div class="table-conter">
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_UPDATENODE">
                <a href="javascript:void(0)" onclick="openUpdateNode('inProcessTable','')"
                   class="layui-btn layui-btn-mini" btnauthCode="ZZSC_INPROCESS_UPDATENODE">更新节点</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_SUSPEND">
                <a href="javascript:void(0)" onclick="suspendOrder('inProcessTable','')"
                   class="layui-btn layui-btn-mini" btnauthCode="ZZSC_INPROCESS_SUSPEND">生产暂停</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_ADD_ASSIST">
                <a href="javascript:void(0)" onclick="addAssist('inProcessTable','')"
                   class="layui-btn layui-btn-mini" btnauthCode="ZZSC_INPROCESS_ADD_ASSIST">添加协单人员</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_CHARGE_BACK">
                <a href="javascript:void(0)" onclick="chargeBackOrder('inProcessTable','')"
                   class="layui-btn layui-btn-mini" btnauthCode="ZZSC_INPROCESS_CHARGE_BACK">退单</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_CERTIFICATE_MATCH">
                <a href="javascript:void(0)" class="layui-btn layui-btn-mini"
                   onclick="certificateMatch('inProcessTable','')"
                   btnauthCode="ZZSC_INPROCESS_CERTIFICATE_MATCH">证书匹配</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_QUALIFICATION_MATCH">
                <a href="javascript:void(0)" class="layui-btn layui-btn-mini"
                   onclick="qualificationMatch('inProcessTable','')" btnauthCode="ZZSC_INPROCESS_QUALIFICATION_MATCH">资质匹配</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_PAY_MONEY">
                <a href="javascript:void(0)" class="layui-btn layui-btn-mini" btnauthCode="ZZSC_INPROCESS_PAY_MONEY"
                   onclick="applyMoneyProduct('inProcessTable','')">费用申请</a>
            </d:hasUrlAuth>
            <%--<d:hasUrlAuth authCode="ZZSC_INPROCESS_BIND_FILES">--%>
                <%--<a href="javascript:void(0)" class="layui-btn layui-btn-mini" btnauthCode="ZZSC_INPROCESS_BIND_FILES"--%>
                   <%--onclick="bindFiles('inProcessTable')">档案绑定</a>--%>
            <%--</d:hasUrlAuth>--%>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_TRANSFER_ORDER">
                <a href="javascript:void(0)" class="layui-btn layui-btn-mini"
                   onclick="transferOrderAjaxSubmit('inProcessTable','')" btnauthCode="ZZSC_INPROCESS_TRANSFER_ORDER">转单</a>
            </d:hasUrlAuth>
            <d:hasUrlAuth authCode="ZZSC_INPROCESS_TURN_OVER">
                <a href="javascript:void(0)" class="layui-btn layui-btn-mini"
                   onclick="turnoverProductOrder('inProcessTable','')" btnauthCode="ZZSC_INPROCESS_TURN_OVER">移交</a>
            </d:hasUrlAuth>
            <div class="fr other-span">
                <div class="fr other-span">
                    <span class="bgRed">订单超期</span>
                    <span class="bgBlue">节点超期</span>
                </div>
            </div>
            <div class="dataTables_wrapper no-footer">
                <!--表格 end-->
                <table class="cell-border crm-table columnsHidden" id="inProcessTable">
                    <thead>
                    <tr>
                        <th><input type="checkbox" class="checkall"/></th>
                        <th width="60">序号</th>
                        <th width="70">订单来源</th>
                        <th width="100">生产订单编号</th>
                        <th>订单编号</th>
                        <th width="130">客户</th>
                        <th width="100">当前完成节点</th>
                        <th>业务类型</th>
                        <th width="80">产品类型</th>
                        <th width="100">签单时间</th>
                        <th width="100">签单商务</th>
                        <th width="100">签单部门</th>
                        <th width="100">流程人员</th>
                        <th width="100">流程部门</th>
                        <th width="130">协单人员</th>
                        <th width="70">合同金额(元)</th>
                        <th width="190">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
    <jsp:include page="/WEB-INF/jsp/footer.jsp"/>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/inprocess/inprocess_list.js?v=${version}"></script>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_common.js?v=${version}"></script>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_flowuser.js?v=${version}"></script>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_divisionUser.js?v=${version}"></script>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_origin_type.js?v=${version}"></script>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_receive.js?v=${version}"></script>
    <script type="text/javascript" src="${basePath}/static/js/zzsc/common/call_common.js?v=${version}"></script>
    <script src="${rootUrl}/static/js/zzsc/common/sc_chooseUser.js?v=${version}" type="text/javascript" charset="utf-8"></script>
    <script src="${rootUrl}/static/js/zzsc/credential/credentailCommon/credentailCommon.js?v=${version}" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
        Plug.plug_ins("post", "${basePath}/zzsc/common/tree_book_list.do?code=BUS_YT_ZZ&&type=2&&level=3", "#business_typeCode", '选择业态', '', true, 'BUS_YT_ZZ', '', '');
        var table;
        $(document).ready(function () {
            //初始化dataTable列表
            table = $('#inProcessTable').dataTableExtend({
                "ajax": {
                    "url": "${basePath}/zzsc/inprocess/query_exceed_list.do",
                    "type": "post"
                },
                "fnServerParams": function (aoData) {
                    aoData = $.extend(aoData, getSearchData());
                    return aoData;
                },
                "scrollX": "true",//是否开启横项滚动
                "fixedColumns": {//锁定列，只有开启scrollX时才生效
                    "leftColumns": 4,//左侧锁定2列
                    "rightColumns": 1//右侧锁定1列
                },
                "aoColumns": [
                    {
                        "orderable": false,
                        "data": "id",
                        "render": function (data, type, full, meta) {
                            return '<input type="checkbox"  name="ids" class="checkchild"  value="' + data + '" />';
                        }
                    }
                    ,
                    {
                        "orderable": false,
                        "render": function (data, type, full, meta) {
                            return meta.row + 1;
                        }
                    }, {//订单来源
                        "orderable": false,
                        "data": "signOrgName"
                    },  {//生产订单编号
                        "orderable": false,
                        "data": "scProductOrderNo",
                        "render": function (data, type, row) {
                                var result ="";
                                result += '<a href="javascript:;"  class="layui-table-link" onclick="openOrderInfoDetail(\'' + row.scProductOrderNo + '\',\'' + row.id + '\')" /><p>' + data + '</p></a>';
                                var reservationStatus = row.reservationStatus;
                                if (reservationStatus){
                                    var split = reservationStatus.split(',');
                                    for (var i = 0; i < split.length;i++){
                                        var splitElement = split[i];
                                        if ('PRODUCT_RESERVATION_STATUS_01' === splitElement){//预约
                                            result += '<a href="javascript:;"   class="label label-yellow" onclick="certificateAppointment(\'' + row.id + '\')">'+'已预约'+'</a>';
                                        }else if ('PRODUCT_RESERVATION_STATUS_02' === splitElement){//预定
                                            result += '<a href="javascript:;"   class="label label-green" onclick="openCertificateMatch(\'' + row.id + '\')">'+'已预定'+'</a>';
                                        }
                                    }
                                }

                                return result;
                        }
                    }, {
                        "orderable": false,
                        "data": "orderNo",
                        "render": function (data, type, full, meta) {
                            return ('<a href=\'javascript:void(0)\' ti  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span class="layui-table-link">' + data + '</span></a>&nbsp;');
                        }
                    },{//客户
                        "orderable": false,
                        "data": "customerName",
                        "render": function (d, type, r) {
                            return emptyStringConvert(d) + '<p>' + emptyStringConvert(r.customerPhone) + '</p>';
                        }
                    }, {//当前完成节点
                        "orderable": false,
                        "data": "latestEndNodeName"
                    }, {//业务
                        "orderable": false,
                        "data": "businessProductName"
                    }, {//产品类型
                        "orderable": false,
                        "data": "productName"
                    }, {//签单时间
                        "orderable": false,
                        "data": "orderTime"
                    },{//签单商务
                        "orderable": false,
                        "data": "signUserName"
                    },{//签单部门
                        "orderable": false,
                        "data": "signUserOrgName"
                    },
                    { //流程人员
                        "orderable": false,
                        "data": "flowUserName"
                    }, { //流程部门
                        "orderable": false,
                        "data": "flowUserOrgName",
                        "render": function (d, type, r) {
                            return r.flowUserOrgName ? '<p class="line2">' + r.flowUserOrgName + '</p>' : '';
                        }
                    }, { //协单人员
                        "sClass": "hoverProcess",
                        "orderable": false,
                        "data": "assistUserName",
                        "render": function (d,type,r) {
                            var names = '';
                            if (d){
                                var split = d.split(",");
                                names='<span>'+split[0]+'</span>';
                                if(split.length>1) {
                                    names+='<i>...</i>'
                                }
                            }
                            return names;
                        }
                    }, {//合同金额
                        "orderable": false,
                        "data": "money"
                    }, {
                        "orderable": false,
                        "data": "id",
                        "width": "190",
                        "render": function (d, type, r, meta) {
                            var result = "";
                            //打电话
                            result += '<a href=\'javascript:void(0)\' ti  onclick="callPhoneByProduction(\'' + r.id + '\')" /><span class="layui-table-link" style="font-weight: bold">打电话</a>&nbsp;&nbsp;&nbsp;';
                            result += '<a href=\'javascript:void(0)\' ti  onclick="remarkLayer(\'' + r.id + '\',\'' + r.nodeFlowId + '\',\'SC_GENERAL_REMARKS_CODE9\' )" /><span class="layui-table-link" style="font-weight: bold">备注</a>';//备注
                            return result;
                        }
                    }], "columnDefs": [{
                    targets: [2], //第1，2，3列
                    createdCell: function (td, cellData, rowData, row, col) {
                        var nodestatus = rowData.nodeTimeStatus;
                        var orderstatus = rowData.orderTimeStatus;
                        if ("OVERDUE_STATE2" == orderstatus) { // ??超期颜色
                            $(td).parent().addClass("bgRed");
                            return;
                        }
                        if ("OVERDUE_STATE2" == nodestatus) {
                            $(td).parent().addClass("bgBlue");
                            return;
                        }
                    }
                }, {
                    targets: ["_all"], "defaultContent": ""
                }]
            });
            $('.title-tab').on('click', 'a', null, function () {
                var $this = $(this);
                var status = $this.attr('data-status');
                var href = window.location.href;
                if (href.indexOf('status=') > -1) {
                    href = href.substring(0, href.indexOf('status=') - 1);
                }
                window.location.href = href + (href.indexOf('?') > -1 ? '&' : '?') + 'status=' + status;
            });

            $(document).on('mouseenter','.hoverProcess',function () {
                var datas=table.cell( this ).data();
                if(datas==undefined) {
                    return false;
                }
                datas = datas.split(",");
                var _top=$(this).offset().top+$(this).height()+'px',
                    _left=$(this).offset().left+'px';
                if(datas!=undefined&&datas.length>1) {
                    var htm='<div class="process-relative" id="processRel" style="top:'+_top+';left:'+_left+'">'
                    for (var i in datas){
                        htm+= '<p class="line2">'+datas[i]+'</p>';
                    }
                    htm+='</div>'
                }
                $('#processRel').remove();
                $('body').append(htm)
            });
            $(document).on('mouseleave','#processRel',function () {
                $('#processRel').remove();
            });
            $(document).on('click',function (e) {
                var case1=$(e.target).parents('.hoverProcess').length,
                    case2=$(e.target).hasClass('.hoverProcess'),
                    case3=$(e.target).parents('#processRel').length;
                if(case3!=1) {
                    $('#processRel').remove();
                }
            });
            //初始化订单来源
            signOrgTreeBookCode('.signUserOrgClass');
            //初始化来源方式
            commonTreeBookCode("#originCode","ORDER_SOURCE",1,1,1,true);
            //初始化签单商务
            chooseUserPlug.init($('#signUserId'), {
                width: '150px',
                select: false,
                url: sysInfo.basePath + '/zzsc/common/find_user_choose.do',
                // multiple:true,// 单选false或不写该参数，多选true
                otherParam: {
                    /**
                     * type: 用户信息选择类型（必填）
                     *       all:全部用户，division：当前登录人所在事业部，department:当前登录人所在部门及以下，role: 查询指定角色用户，
                     * roleCode : 角色Code，（type为role时，必填）
                     * locked: 用户状态，（选填，默认全部状态）
                     *      0、正常；1、锁定；2、离职
                     */
                    type: 'all',
                    length: 50,
                    start:0
                }
            });
        });

        function signOrgTreeBookCode(obj) {
            $(obj).find("option").remove();
            $(obj).append("<option value=''>请选择</option>");
            $.post(sysInfo.basePath + '/zzsc/common/find_all_syb.do', function (result) {
                if (result.code == 0) {
                    $.each(result.data, function (i, item) {
                        $(obj).append("<option value='" + item.id + "'>" + item.name + "</option>");
                    });
                } else {
                    DGG.Errors("系统错误，请联系管理员");
                }
            });
            $(obj).select2({
                placeholder: "请选择",
                allowClear: true,
                width: "150px",
                language: "zh-CN"
            });
        }


        //导出办理中数据
        function exportIprocessData() {
            var paras = $('.titleSearch').serialize2object();
            if (Object.keys(paras).length == 0) {
                DGG.Warning('请加入搜索条件后导出！');
                return;
            }
            $.extend(paras, {type: $(".title-tab").find("a.active").attr("data-status")});
            exportDataAbandoned('/zzsc/inprocess/export_inprocess_product_order.do', paras);
        }


        // 获取搜索数据
        function getSearchData() {
            return $.extend({type: $('#type').val()}, $('.titleSearch').serializeJson());
        }
        //获取选中ID
        function getSelectIds() {
            var data = $('#inProcessTable').dataTableExtend('getCheck');
            var checkedIds = new Array();
            $.each(data, function (i, n) {
                checkedIds.push(n.id);
            });
            return checkedIds;
        }


    </script>
</div>
</body>
</html>
